﻿using System.Collections.Generic;
using System.Linq;
using Fit2ModelsFluent;
using NHibernate;

namespace Fit2InfrastructureFluent
{
    public class QuestionRepository : IQuestionRepository
    {
        private ISession GetSession()
        {
            var cache = new SessionCache();
            ISession session = cache.GetSession();
            return session;
        }
        #region IQuestionRepository Members

        public void Save(Question question)
        {
            ISession session = GetSession();
            session.SaveOrUpdate(question);
        }

        public void SaveUsingTransaction(Question question)
        {
            ISession session = GetSession();
            using (var t = session.BeginTransaction())
            {
                session.SaveOrUpdate(question);
                t.Commit(); 
            }
        }

        public List<Question> GetAllQuestions()
        {
            throw new System.NotImplementedException();
        }

        #endregion

        #region IQuestionRepository Members


        public Question GetQuestion(System.Guid QuestionId)
        {
            ISession session = GetSession();
            Question question = (Question)session.Load(typeof(Question), QuestionId, LockMode.Upgrade);
            return question;
        }

        #endregion
    }
}
